home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue55 / Clinic / ListViewEx2.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-01-03  |  1.4 KB  |  63 lines

  1. unit ListViewEx2;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, Classes, Controls, ComCtrls, CommCtrl;
  7.  
  8. type
  9.   //This is a variation on the wm_Notify message record
  10.   //that is used for certain listview notification messages
  11.   TWMListViewNotify = packed record
  12.     Msg: Cardinal;
  13.     IDCtrl: Longint;
  14.     NMLV: PNMListView;
  15.     Result: Longint;
  16.   end;
  17.  
  18.   TItemCheckEvent = procedure (Sender: TCustomListView;
  19.     Item: TListItem; Checked: Boolean) of object;
  20.  
  21.   TListViewEx2 = class(TListView)
  22.   private
  23.     FOnCheck: TItemCheckEvent;
  24.   protected
  25.     procedure CNNotify(var Msg: TWMListViewNotify);
  26.       message cn_Notify;
  27.   published
  28.     property OnCheck: TItemCheckEvent read FOnCheck write FOnCheck;
  29. end;
  30.  
  31. procedure Register;
  32.  
  33. implementation
  34.  
  35. procedure Register;
  36. begin
  37.   RegisterComponents('Clinic', [TListViewEx2]);
  38. end;
  39.  
  40. { TListViewEx2 }
  41.  
  42. procedure TListViewEx2.CNNotify(var Msg: TWMListViewNotify);
  43. const
  44.   OldChecked: Boolean = False;
  45.   OldItem: Integer = -1;
  46. begin
  47.   with Msg.NMLV^ do
  48.     case hdr.code of
  49.       LVN_ITEMCHANGING:
  50.       begin
  51.         Olditem := iItem;
  52.         OldChecked := Items[OldItem].Checked;
  53.       end;
  54.       LVN_ITEMCHANGED:
  55.         if (iItem = OldItem) and (Items[iItem].Checked <> OldChecked) and
  56.            Assigned(FOnCheck) then
  57.           FOnCheck(Self, Items[iItem], Items[iItem].Checked)
  58.     end;
  59.   inherited;
  60. end;
  61.  
  62. end.
  63.